package net.hnjdzy.newsclient.manager;

import com.alibaba.fastjson.JSON;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import net.hnjdzy.newsclient.entity.Topic;

import java.io.IOException;
import java.util.List;

public class TopicManager {
    final static String url =Constants.URL_GET_NEWS_LIST;
    public List<Topic> getTopicList() {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(url).build();
        try {
            Response response = client.newCall(request).execute();
            String json = response.body().string();
            List<Topic> result = JSON.parseArray(json, Topic.class);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
